(function () {
    if (!window.jQuery || Object.prototype.toString.call(window.jQuery) != "[object Function]") {
        window.onload = function () {
            var a = document.getElementById("nojquery");
            if (a) {
                a.style.display = "block"
            }
        }
    }
})();
(function () {
    if (!window.console) {
        var b, a = ["assert", "count", "debug", "dir", "dirxml", "error", "group", "groupCollapsed", "groupEnd", "info", "log", "markTimeline", "profile", "profileEnd", "table", "time", "timeEnd", "trace", "warn"];
        window.console = {};
        for (b = a.length; b--;) {
            window.console[a[b]] = function () {
            }
        }
    }
})();
var ADDRESS_STREET_PREFIXES = "", ALLOW_LETTERS = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZабвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯЄІЇєіїҐґ'\\[\\]0123456789.", BANNER_MINUS_WORDS_LIMIT = 2048, CAMPAIGN_MINUS_WORDS_LIMIT = 4096, KAZ_LETTERS = "ҰҒғӨҢҚҺҮұөңқһүҖҲҳҗӘә", MAX_AUTOBUDGET = 10000000, MAX_AUTOBUDGET_BID = 50, MAX_AUTOBUDGET_CLICKS_BUNDLE = 1000000000, MAX_PHRASE_RANK_WARNING = 7000, MAX_PRICE = 50, MAX_TAGS_FOR_CAMPAIGN = 30, MAX_TAG_LENGTH = 25, MAX_URL_LENGTH = 1024, MIN_AUTOBUDGET = 10, MIN_AUTOBUDGET_AVG_PRICE = 0.03, MIN_AUTOBUDGET_BID = 0.01, MIN_AUTOBUDGET_CLICKS_BUNDLE = 100, MIN_GOALS_ON_CAMPAIGN = 50, MIN_PHRASE_RANK_WARNING = 2, MIN_PRICE = 0.01, RUS_LETTERS = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ", SITELINKS_MAX_LENGTH = 66, SITELINKS_NUMBER = 3, UKR_NATIVE_LETTERS = "ЄІЇєіїҐґ", currencies = {KZT:{MAX_AUTOBUDGET_CLICKS_BUNDLE:1000000000, MIN_DAY_BUDGET:1500, MAX_TOPAY_SUGGEST:75000, MAX_PRICE:7500, MIN_AUTOBUDGET_CLICKS_BUNDLE:100, MIN_AUTOBUDGET_BID:1.5, MIN_PRICE:1.5, MIN_PRICE_FOR_MFA:7.5, name:"тенге", BALANCE_CURRENCY_NAME:"KZT", full_name:"казахстанские тенге", MIN_SERVICED_PAY:45000, DIRECT_DEFAULT_PAY:7500, MIN_PAY:1500, MIN_AUTOBUDGET_AVG_PRICE:4.5, MIN_TRANSFER_MONEY:1500, MAX_AUTOBUDGET:1500000000, MIN_AUTOBUDGET:1500, pay_in:"Оплатить в тенге", MAX_AUTOBUDGET_BID:7500}, EUR:{MAX_AUTOBUDGET_CLICKS_BUNDLE:1000000000, MIN_DAY_BUDGET:10, MAX_TOPAY_SUGGEST:500, MAX_PRICE:50, MIN_AUTOBUDGET_CLICKS_BUNDLE:100, MIN_AUTOBUDGET_BID:0.01, MIN_PRICE:0.01, MIN_PRICE_FOR_MFA:0.05, name:"евро", BALANCE_CURRENCY_NAME:"EUR", full_name:"евро", MIN_SERVICED_PAY:300, DIRECT_DEFAULT_PAY:50, MIN_PAY:10, MIN_AUTOBUDGET_AVG_PRICE:0.03, MIN_TRANSFER_MONEY:10, MAX_AUTOBUDGET:10000000, MIN_AUTOBUDGET:10, pay_in:"Оплатить в евро", MAX_AUTOBUDGET_BID:50}, YND_FIXED:{MAX_AUTOBUDGET_CLICKS_BUNDLE:1000000000, MIN_DAY_BUDGET:10, MAX_TOPAY_SUGGEST:500, MAX_PRICE:50, MIN_AUTOBUDGET_CLICKS_BUNDLE:100, MIN_AUTOBUDGET_BID:0.01, MIN_PRICE:0.01, MIN_PRICE_FOR_MFA:0.05, name:"у.е.", BALANCE_CURRENCY_NAME:null, full_name:"условные единицы", MIN_SERVICED_PAY:300, DIRECT_DEFAULT_PAY:50, MIN_PAY:10, MIN_AUTOBUDGET_AVG_PRICE:0.03, MIN_TRANSFER_MONEY:10, MAX_AUTOBUDGET:10000000, MIN_AUTOBUDGET:10, pay_in:"Оплатить", MAX_AUTOBUDGET_BID:50}, UAH:{MAX_AUTOBUDGET_CLICKS_BUNDLE:1000000000, MIN_DAY_BUDGET:50, MAX_TOPAY_SUGGEST:2500, MAX_PRICE:250, MIN_AUTOBUDGET_CLICKS_BUNDLE:100, MIN_AUTOBUDGET_BID:0.05, MIN_PRICE:0.05, MIN_PRICE_FOR_MFA:1.5, name:"грн.", BALANCE_CURRENCY_NAME:"UAH", full_name:"украинские гривны", MIN_SERVICED_PAY:1500, DIRECT_DEFAULT_PAY:250, MIN_PAY:50, MIN_AUTOBUDGET_AVG_PRICE:0.15, MIN_TRANSFER_MONEY:50, MAX_AUTOBUDGET:50000000, MIN_AUTOBUDGET:50, pay_in:"Оплатить в украинских гривнах", MAX_AUTOBUDGET_BID:250}, RUB:{MAX_AUTOBUDGET_CLICKS_BUNDLE:3000000000, MIN_DAY_BUDGET:300, MAX_TOPAY_SUGGEST:15000, MAX_PRICE:1500, MIN_AUTOBUDGET_CLICKS_BUNDLE:100, MIN_AUTOBUDGET_BID:0.1, MIN_PRICE:0.1, MIN_PRICE_FOR_MFA:1.5, name:"руб.", BALANCE_CURRENCY_NAME:null, full_name:"российские рубли", MIN_SERVICED_PAY:9000, DIRECT_DEFAULT_PAY:1500, MIN_PAY:300, MIN_AUTOBUDGET_AVG_PRICE:0.3, MIN_TRANSFER_MONEY:300, MAX_AUTOBUDGET:300000000, MIN_AUTOBUDGET:300, pay_in:"Оплатить в российских рублях", MAX_AUTOBUDGET_BID:1500}, USD:{MAX_AUTOBUDGET_CLICKS_BUNDLE:1000000000, MIN_DAY_BUDGET:10, MAX_TOPAY_SUGGEST:500, MAX_PRICE:50, MIN_AUTOBUDGET_CLICKS_BUNDLE:100, MIN_AUTOBUDGET_BID:0.01, MIN_PRICE:0.01, MIN_PRICE_FOR_MFA:0.05, name:"долл. США", BALANCE_CURRENCY_NAME:"USD", full_name:"доллары США", MIN_SERVICED_PAY:300, DIRECT_DEFAULT_PAY:50, MIN_PAY:10, MIN_AUTOBUDGET_AVG_PRICE:0.03, MIN_TRANSFER_MONEY:10, MAX_AUTOBUDGET:10000000, MIN_AUTOBUDGET:10, pay_in:"Оплатить в долларах США", MAX_AUTOBUDGET_BID:50}};
/*
 jQuery Waypoints - v1.0.2
 Copyright (c) 2011 Caleb Troughton
 Dual licensed under the MIT license and GPL license.
 https://github.com/imakewebthings/jquery-waypoints/blob/master/MIT-license.txt
 https://github.com/imakewebthings/jquery-waypoints/blob/master/GPL-license.txt
 */
(function ($, q, u, b, g) {
    var e = $(b), n = [], s = -99999, a = false, o = false, h = "waypoint.reached", c = {init:function (w, v) {
        this.each(function () {
            var A = $(this), x = j(A), z = x < 0 ? $.fn[q].defaults : n[x].options, y = $.extend({}, z, v);
            y.offset = y.offset === "bottom-in-view" ? function () {
                return $[u]("viewportHeight") - $(this).outerHeight()
            } : y.offset;
            if (x < 0) {
                n.push({element:A, offset:A.offset().top, options:y})
            } else {
                n[x].options = y
            }
            w && A.bind(h, w)
        });
        $[u]("refresh");
        return this
    }, remove:function () {
        return this.each(function () {
            var v = j($(this));
            if (v >= 0) {
                n.splice(v, 1)
            }
        })
    }, destroy:function () {
        return this.unbind(h)[q]("remove")
    }};

    function j(w) {
        var v = n.length - 1;
        while (v >= 0 && n[v].element[0] !== w[0]) {
            v -= 1
        }
        return v
    }

    function m(w, v) {
        w.element.trigger(h, v);
        if (w.options.triggerOnce) {
            w.element[q]("destroy")
        }
    }

    function d() {
        var w = e.scrollTop(), x = w > s, v = $.grep(n, function (z, y) {
            var A = z.options.approximation || 0;
            return x ? (z.offset > s - A && z.offset <= w + A) : (z.offset <= s + A && z.offset > w - A)
        });
        if (!s || !w) {
            $[u]("refresh")
        }
        s = w;
        if (!v.length) {
            return
        }
        if ($[u].settings.continuous) {
            $.each(x ? v : v.reverse(), function (z, y) {
                m(y, [x ? "down" : "up"])
            })
        } else {
            m(v[x ? v.length - 1 : 0], [x ? "down" : "up"])
        }
    }

    $.fn[q] = function (v) {
        if (c[v]) {
            return c[v].apply(this, Array.prototype.slice.call(arguments, 1))
        } else {
            if (typeof v === "function" || !v) {
                return c.init.apply(this, arguments)
            } else {
                if (typeof v === "object") {
                    return c.init.apply(this, [null, v])
                } else {
                    $.error("Method " + v + " does not exist on jQuery" + q)
                }
            }
        }
    };
    $.fn[q].defaults = {offset:0, triggerOnce:false};
    var l = {refresh:function () {
        $.each(n, function (x, A) {
            var z = "";
            if (A === g) {
                return
            }
            var w = 0, y = A.offset;
            if (typeof A.options.offset === "function") {
                w = A.options.offset.apply(A.element)
            } else {
                if (typeof A.options.offset === "string") {
                    var v = parseFloat(A.options.offset), w = A.options.offset.indexOf("%") ? Math.ceil($[u]("viewportHeight") * (v / 100)) : v
                } else {
                    w = A.options.offset
                }
            }
            A.offset = A.element.offset().top - w;
            if (s > y && s <= A.offset) {
                m(A, ["up"])
            } else {
                if (s < y && s >= A.offset) {
                    m(A, ["down"])
                }
            }
        });
        n.sort(function (w, v) {
            return w.offset - v.offset
        })
    }, viewportHeight:function () {
        return(b.innerHeight ? b.innerHeight : e.height())
    }, aggregate:function () {
        var v = $();
        $.each(n, function (w, x) {
            v = v.add(x.element)
        });
        return v
    }};
    $[u] = function (v) {
        if (l[v]) {
            return l[v].apply(this)
        } else {
            return l.aggregate()
        }
    };
    $[u].settings = {continuous:true, resizeThrottle:200, scrollThrottle:100};
    e.scroll(
        function () {
            if (!a) {
                a = true;
                b.setTimeout(function () {
                    d();
                    a = false
                }, $[u].settings.scrollThrottle)
            }
        }).resize(
        function () {
            if (!o) {
                o = true;
                b.setTimeout(function () {
                    $[u]("refresh");
                    o = false
                }, $[u].settings.resizeThrottle)
            }
        }).load(function () {
        $[u]("refresh");
        d()
    })
})(jQuery, "waypoint", "waypoints", this);
$(function () {
    $(".g-deferred").waypoint(function () {
        var d = $(this), c = this.onclick ? this.onclick() : {}, a = c.name || "", b = Lego.block[a];
        if (b && !d.data(a)) {
            b.call(d, c);
            d.data(a, true).addClass(a + "_js_inited")
        }
    }, {offset:function () {
        return $.waypoints("viewportHeight") - 50
    }, triggerOnce:true})
});
common = this.common || {};
(function () {
    common.format = {number:function (h, e, c, d, g) {
        h = h || 0;
        e = e || 0;
        c = c || "";
        d = d || ".";
        var b = "";
        h = a(h, e, g).replace(".", d);
        while ((b = h.replace(/(\d)(\d\d\d)($|\D)/, "$1" + c + "$2$3")) != h) {
            h = b
        }
        return h
    }, href:function (c, d) {
        if (!c || c.match(/^#/)) {
            return c
        }
        if (!c.match(/^https?:\/\//)) {
            c = "http://" + c
        }
        if (d) {
            var b = c.match(/\?/) ? "&" : "?";
            c = c.replace(/($|\#)/, b + "_openstat=dGVzdDsxOzE7$1")
        }
        return c
    }, trim:function (c, b) {
        if (c.length > b) {
            return c.substr(0, b - 1) + "\u2026"
        }
        return c
    }};
    function a(j, g, h) {
        var e = Math.pow(10, g);
        if (h == "toMin") {
            j = Math.floor(j * e) / e + ""
        } else {
            j = Math.round(j * e) / e + ""
        }
        if (g == 0) {
            return j
        }
        var m = j.indexOf(".");
        var d = 0;
        if (m == -1) {
            j += ".";
            d = g
        } else {
            d = g - (j.length - m - 1)
        }
        for (var c = 0, b = d; c < b; c++) {
            j += "0"
        }
        return j
    }
})();
common.parse = {number:function (a, b) {
    a = (a + "").replace(/[,\.юЮбБ]/gi, ".").replace(/[^0-9\.\-]/g, "");
    return b ? common.format.number(a, b) : +a
}};
(function () {
    var a = "/registered/main.pl";
    common.validate = {phrases:function (b) {
        var c = {valid:false, message:""};
        $.ajax({type:"POST", dataType:"json", async:false, url:a, data:{cmd:"ajaxValidatePhrasesForForecast", phrases:b}, error:function (g, h, d) {
            c.valid = false
        }, success:function (d, g, e) {
            c.message = d.error || "";
            c.valid = !("error" in d)
        }});
        return c
    }}
})();
common.inflector = new function () {
    this.pluralize = function (c, b) {
        var a = arguments, d = 0;
        return c.replace(/(\%[df])(([^\{%]*)\{([^\{]+)\})?/, function () {
            d++;
            if (arguments[2]) {
                return a[d] + arguments[3] + common.inflector.pluralizeWord(arguments[4].split("|"), a[arguments[1] == "%f" ? ++d : d])
            } else {
                return a[d]
            }
        })
    };
    if (window.Direct_lang == "ru" || window.Direct_lang == "ua") {
        this.pluralizeWord = function (a, b) {
            b %= 100;
            if (b >= 5 && b <= 20) {
                return a[2]
            }
            b %= 10;
            if (b == 1) {
                return a[0]
            } else {
                if (b < 5 && b > 0) {
                    return a[1]
                }
            }
            return a[2]
        }
    } else {
        if (window.Direct_lang == "en") {
            this.pluralizeWord = function (a, b) {
                if (b == 1) {
                    return a[0]
                }
                return a[1]
            }
        }
    }
};
common.loader = {_loaded:{}, _loading:{}, _callbacks:[], _map:{}, _queue:[], load:function (b, d) {
    var c = [];
    for (var a = 0; a < b.length; a++) {
        c[a] = this._mapToUrl(b[a]);
        this._queue.push(c[a])
    }
    this._callbacks.push([c, d]);
    common.loader._notifyCallbacks();
    this._loadNext()
}, _notifyCallbacks:function () {
    var c = [];
    for (var b = 0; b < this._callbacks.length; b++) {
        var d = this._callbacks[b];
        for (var a = 0...e:
        "b-form-button", modName
    :
        "val", modVal
    :
        "restore"
    }
    ))
    ;
    this.restoreBtn && this.restoreBtn.on("click", this.onRestore, this)
}
this.setMod("deleted", c ? "yes" : "no")
}},
{
    live:true
}
)})
(jQuery);
(function (a) {
    BEM.DOM.decl({name:"b-edit-phrase-price", baseBlock:"b-model-block"}, {onSetMod:{js:function () {
        this.initConsts();
        this.initModel()
    }}, initConsts:function () {
        this._modelPath = this.params.modelPath;
        this._modelName = "b-phrases-list-phrase"
    }, updatePhrasePriceStyles:function (b) {
        this.delMod("error");
        this.delMod("warning");
        if (b == "" || isNaN(b)) {
            this.setMod("error", "yes")
        } else {
            if (b < MIN_PRICE) {
                this.setMod("error", "yes")
            } else {
                if (b > 10) {
                    this.setMod("warning", "yes")
                }
            }
        }
    }}, {live:true})
})(jQuery);
(function (a) {
    BEM.DOM.decl({name:"b-edit-phrase-price", modelName:"strategy", modVal:"autobudget"}, {onSetMod:{js:function () {
        var b = this;
        b.initConsts();
        b.initModel();
        this.model.onField("autobudgetPriority", "change", this.onAutobudgetPriorityChange, this);
        b.elem("autobudget-link").length > 0 && b.bindTo("autobudget-link", "click", this.togglePopup);
        b.onAutobudgetPriorityChange()
    }}, getPopup:function () {
        return this.popup || (this.popup = BEM.blocks["b-phrases-list-phrase-autobudget"].getInstance())
    }, togglePopup:function () {
        var b = this;
        if (this.getPopup().isShowed()) {
            this.popup.hide()
        } else {
            this.popup.show(this.elem("autobudget-link"), this.model.get("autobudgetPriority"), function (c) {
                b.model.set("autobudgetPriority", c)
            })
        }
    }, onAutobudgetPriorityChange:function (d, c) {
        if (this.model.get("deleted")) {
            return
        }
        var b = this.model.get("autobudgetPriority");
        this.elem("autobudget-hidden").val(b);
        this.updateTexts(b)
    }, updateTexts:function (b) {
        var c = b == 1 ? iget("низкий") : b == 5 ? iget("высокий") : iget("средний");
        this.elem("autobudget-text").html(c);
        this.elem("autobudget-text-view") && this.elem("autobudget-text-view").html(c)
    }})
})(jQuery);
(function (a) {
    BEM.DOM.decl({name:"b-edit-phrase-price", modName:"strategy", modVal:"context"}, {onSetMod:{js:function () {
        var b = this;
        b.initConsts();
        b.initModel();
        b.bindEvents(["price_context"], []);
        b.model.onField("price_context", "change", b.onContextPriceChanged, b);
        b.model.onField("autobroker", "change", b.onContextAutobrokerChanged, b);
        b.onContextPriceChanged()
    }}, updateContextCoverage:function () {
        if (this.model.get("no_pokazometer_stat") == 1 || !this.model.get("pokazometer_data") || !this.model.get("pokazometer_data").shows_list || this.model.get("pokazometer_data").shows_list.length < 1) {
            return
        }
        var b = direct.autobroker.calcContextCoverage(this.model.get("price_context") * 1000000, this.model.get("pokazometer_data"));
        this.elem("coverage").html(common.number.format(b * 100, {precision:0}) + "%")
    }, onContextPriceChanged:function () {
        if (this.model.get("deleted") || this.model.get("delete_complete")) {
            return
        }
        this.elem("price-context").val(this.model.view("price_context"));
        this.updatePhrasePriceStyles(this.model.get("price_context"));
        this.updateContextCoverage();
        this.elem("price-context-view") && this.elem("price-context-view").html(this.model.view("price_context"))
    }, onContextAutobrokerChanged:function (c, b) {
        if (this.model.get("deleted") || this.model.get("delete_complete")) {
            return
        }
        this.updateContextCoverage()
    }})
})(jQuery);
(function (a) {
    BEM.DOM.decl({name:"b-edit-phrase-price", modName:"strategy", modVal:"search"}, {onSetMod:{js:function () {
        var b = this;
        b.initConsts();
        b.initModel();
        b.bindEvents(["price"], []);
        b.bindTo("autobroker", "click", function () {
            b.model.update({autobroker:+b.elem("autobroker").attr("checked")}, b);
            b.updateSearchPrice()
        });
        b.model.onField("price", "change", b.onPriceChanged, b);
        b.model.onField("autobroker", "change", b.onAutobrokerChanged, b);
        b.onPriceChanged()
    }}, updateSearchPrice:function () {
        var b = direct.autobroker.calcPrice(this.model.get("price"), this.model.get("arr"), this.model.get("parr"), this.model.get("larr"), this.model.get("min_price"), sum_rest, day_budget, spent_today, strategy, this.model.get("autobroker"), this.params.timetarget_coef);
        this.elem("search-price").html((b.price > 0 && b.place_name != "out" ? common.number.format(b.price) : "&ndash;") + (b.truncated ? '<a href="#" onclick="return OpenWindow(iget(\'/help/text.xml?id=1036137\'), 600, 500)" title="' + iget("Цена ограничена остатком средств на кампании") + '"><img class="b-edit-phrase-price__question" src="/i/icons/question.gif" alt=""/></a>' : "")).css("color", this.model.get("min_price") && this.model.get("price") < this.model.get("min_price") ? "red" : "black").siblings(".b-question-mark").css("visibility", b.truncated || (!b.place_name_without_coef || b.place_name == b.place_name_without_coef) ? "hidden" : "visible");
        this.elem("coverage").html(b.coverage > 0 ? common.number.format(b.coverage * 100, {precision:0}) + "%" : "0%")
    }, onPriceChanged:function () {
        if (this.model.get("deleted") || this.model.get("delete_complete")) {
            return
        }
        this.elem("price").val(this.model.view("price"));
        this.updatePhrasePriceStyles(this.model.get("price"));
        this.updateSearchPrice();
        this.elem("price-view") && this.elem("price-view").html(this.model.view("price"))
    }, onAutobrokerChanged:function (c, b) {
        if (b.source == this) {
            return
        }
        if (this.model.get("deleted") || this.model.get("delete_complete")) {
            return
        }
        this.updateSearchPrice()
    }})
})(jQuery);
